博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[AngularJS] Isolate State Mutations in Angular Components
阅读量:5878 次
发布时间:2019-06-19

本文共 1247 字,大约阅读时间需要 4 分钟。

Managing state is one of the hardest things to do in any application. Angular 2 tackles this problem by making it easy to implement a reactive, uni-directional data flow that favor immutable operations. We are moving in the right direction in Angular 1 by moving our state and logic to models but invariably this raises a question. If we are moving to an immutable world, how do you manage mutable operations like forms in Angular? In this lesson, we are going to learn a surprisingly simple technique to isolate state mutations within a component using component lifecycle hooks.

 

For example you have a bookmark component, and inside the component, you want to update the bookmark. The solution is you create a component just for update bookmark.

 

And inside the save-bookmark component, you can copy the original data, and modify on the copy data:

class SaveController {  $onChanges() {    this.editedBookmark = Object.assign({}, this.bookmark);  }}export default SaveController;

This can isolate the component state muataion. 

转载地址:http://dgdix.baihongyu.com/

你可能感兴趣的文章
SILK 的 Tilt的意思
查看>>
Html学习笔记3
查看>>
批处理学习笔记8 - 深入学习For命令1
查看>>
微信支付开发(11) Native支付
查看>>
HDFS dfsclient写文件过程 源码分析
查看>>
关于多线程的那些事
查看>>
JavaScript获取DOM元素位置和尺寸大小
查看>>
EL 表达式小结
查看>>
内部排序
查看>>
jQuery EasyUI API 中文文档 - 组合(Combo)
查看>>
10个关于 Dropbox 的另类功用(知乎问答精编)[还是转来了]
查看>>
Oracle体系结构
查看>>
用Modelsim仿真QII FFT IP核的时候出现的Error: Illegal target for defparam
查看>>
javascript Error对象详解
查看>>
nc 局域网聊天+文件传输(netcat)
查看>>
每天一个linux命令(25):linux文件属性详解
查看>>
go微服务框架go-micro深度学习(三) Registry服务的注册和发现
查看>>
python 重载方法有哪些特点 - 老王python - 博客园
查看>>
在Fedora8上安装MySQL5.0.45的过程
查看>>
设计模式之命令模式
查看>>